import { Switch } from "antd";
import React from "react";
import { useState } from "react";

/**
 * 
 * @param {onChange} param0 
 * @returns 封装switch组件 使用返回得到"1"或者"0"
 */

const XxSwitch = ({ onChange, defaultChecked = false, ...props }) => {
    const [switchVal, setSwitchVal] = useState(defaultChecked);
    const handleSwitchChange = (value) => {
        console.log("switch组件的onChange接收到的值：", value)
        const newVal = value;
        setSwitchVal(newVal);
        if (onChange) {
            onChange(newVal ? "1" : "0")
        }
    }
    return <Switch
        {...props}
        defaultChecked={switchVal}
        onChange={value => handleSwitchChange(value)}
    />
}

export default XxSwitch;